package com.definesys.smecrailtransit.module.lineCharts;

import android.content.Context;

import com.definesys.smecrailtransit.SmecManager.SmecRetrofit.BaseSubscriber;
import com.definesys.smecrailtransit.SmecManager.SmecRetrofit.HttpResult;
import com.definesys.smecrailtransit.base.SmecBasePresenter;
import com.definesys.smecrailtransit.module.lineCharts.beans.DayReport;
import com.definesys.smecrailtransit.module.lineCharts.beans.MonReport;

import java.util.WeakHashMap;

import rx.Observable;

import static com.definesys.smecrailtransit.module.lineCharts.Fragment.DayChartsFragment.GET_DAY_REPORT_FAILURE;
import static com.definesys.smecrailtransit.module.lineCharts.Fragment.DayChartsFragment.GET_DAY_REPORT_SUCCESS;
import static com.definesys.smecrailtransit.module.lineCharts.Fragment.MonthFragment.GET_MON_REPORT_FAIL;
import static com.definesys.smecrailtransit.module.lineCharts.Fragment.MonthFragment.GET_MON_REPORT_SUCCESS;

/**
 * Created by xupeizuo on 2018/3/5.
 */

public class LineChartsPresenter  extends SmecBasePresenter{

    public LineChartsPresenter(Context mContext) {
        super(mContext);
    }


    /**
     * 获取日报信息
     * @param date
     */
    public void getDayReport(String date){
        WeakHashMap<String,String> map=new WeakHashMap<>();
        map.put("line","12");
//        map.put("date","2017-09-22");
        map.put("date",date);
        Observable<HttpResult<DayReport>> observable=smecRailService.getDayReport(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult<DayReport>>() {
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mRxbus.post(GET_DAY_REPORT_FAILURE,new Object());
            }

            @Override
            public void onNext(HttpResult<DayReport> dayReportHttpResult) {
                mRxbus.post(GET_DAY_REPORT_SUCCESS,dayReportHttpResult.getData());
            }
        });
    }

    /**
     * 获取月报
     * @param date
     */
    public void getMonReport(String date){
        WeakHashMap<String,String> map=new WeakHashMap<>();
//        map.put("date","2017-09");
        map.put("date",date);
        map.put("line","12");
        Observable<HttpResult<MonReport>> observable=smecRailService.getMonReport(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult<MonReport>>() {

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mRxbus.post(GET_MON_REPORT_FAIL,new Object());
            }

            @Override
            public void onNext(HttpResult<MonReport> monReportHttpResult) {
                mRxbus.post(GET_MON_REPORT_SUCCESS,monReportHttpResult.getData());
            }
        });
    }
}
